import http from "./https";

export default {
  getWebConfig: (data: object) => {
    const url = "api/user/config";
    return http.get(url, data)
  },

  login: (data: object) => {
    const url = "api/passport/login";
    return http.post(url, data)
  },

  getUserInfo: () => {
    const url = "api/user/user-info";
    return http.get(url, {})
  },

  getUserLoginStatus: (random_code: string) => {
    const url = "api/code/get-token&random_code=" + random_code;
    return http.get(url, {})
  },

  getLoginCode: () => {
    const url = "api/code/get-code";
    return http.get(url, {})
  },

  // 类目列表
  getCatList: (data: object) => {
    const url = "api/cat/list&cat_id=&select_cat_id=";
    return http.get(url, data)
  },

  // 平台列表
  getPlatformList: (data: object) => {
    const url = "api/platform/list";
    return http.get(url, data)
  },

  // 国家列表
  getCountryList: (data: object) => {
    const url = "api/country/list";
    return http.get(url, data)
  },

  // 模特列表
  getModelList: (data: {
    pageNum: number;
    cat_id: string;
    keyword: string;
    platform_id: string;
    country_id: string;
    sex: string;
    shop_type: number;
  }) => {
    // console.log(data.shop_type);
    const url = `api/default/goods-list&page=${data.pageNum}&keyword=${data.keyword}&platform_id=${data.platform_id}&country_id=${data.country_id}&sex=${data.sex}&cat_id=${data.cat_id}&shop_type=${data.shop_type}&sort=2&sort_type=-1`;
    return http.get(url, data)
  },

  // 模特列表
  getPackageList: () => {
    // console.log(data.shop_type);
    const url = `api/default/goods-list&page=1&keyword=&shop_type=2&sort=2&sort_type=-1`;
    return http.get(url, {})
  },

  getModelDetail: (data: { id: number }) => {
    const url = `api/goods/detail&id=${data.id}&plugin=mall`;
    return http.get(url, {})
  },

  // 收藏列表
  getFavoriteList: (data: {
    pageNum: number;
    keyword: string;
  }) => {
    const url = `api/user/my-new-favorite-goods&cat_id=0&status=0&page=${data.pageNum}`;
    return http.get(url, data)
  },

  // 收藏模特 api/user/favorite-add&goods_id=1
  getFavoriteAdd: (data: { id: number }) => {
    const url = `api/user/favorite-add&goods_id=${data.id}`;
    return http.get(url, {})
  },
  // 取消收藏模特 api/user/favorite-add&goods_id=1
  getFavoriteRemove: (data: { id: number }) => {
    const url = `api/user/favorite-remove&goods_id=${data.id}`;
    return http.get(url, {})
  },


  // 获取规格
  // getOrderAttr: (data: number) => {
  //   const url = `api/goods/attr&id=${data}&mch_id=0`;
  //   return http.get(url, {})
  // },

// {"list":[{"mch_id":0,"goods_list":[{"id":9,"attrs":[{"attr_id":2,"attr_group_id":1}],"num":1,"cat_id":0,"goods_attr_id":9,"cart_id":0}],
// "distance":0,"remark":"","order_form":[],"use_integral":0,"user_coupon_id":0}],"address_id":0,"send_type":""}

// {"list":[{"mch_id":0,"goods_list":[{"id":13,"attrs":[{"attr_id":2,"attr_group_id":1}],"num":1,"cat_id":0,"goods_attr_id":13,"cart_id":0}],
// "distance":0,"remark":"","order_form":[],"use_integral":0,"user_coupon_id":0}],"address_id":0,"send_type":""}

  getOrderPreview: (data: string) => {
    const form_data = {
      form_data: data,
    }
    const url = `api/order/preview`;
    return http.post(url, form_data)
  },

  // 购物车下单
  postOrderSubmit: (data: string, type: number) => {
    const form_data = {
      form_data: data,
      shop_type: type
    }

    const url = `api/order/submit`;
    return http.post(url, form_data)
  },

  postPayData: (data: object) => {
    const url = "api/order/pay-data";
    return http.post(url, data)
  },

  getPaymentPayData: (data: { id: number, type: string }) => {
    // pay_type: balance
    const url = `api/payment/pay-data&id=${data.id}&pay_type=${data.type}`;
    return http.get(url, {})
  },

  getPaymentTotal: (data: number) => {
    const url = `api/payment/get-payments&id=${data}`;
    return http.get(url, {})
  },

  getPaymentBuyBalance: (data: number) => {
    const url = `api/payment/pay-buy-balance&id=${data}&pay_password=""&is_need_pay_password=0`;
    return http.get(url, {})
  },

  getOrderList: (data: { status: number, pageNum: number, shop_type: number }) => {
    const url = `api/order/list&status=${data.status}&keyword=&dateArr=%5B%5D&page=${data.pageNum}&shop_type=${data.shop_type}`;
    return http.get(url, {})
  },

  getGoodsAttr: (data: { id: number, mch_id: number }) => {
    const url = `api/goods/attr&id=${data.id}&mch_id=${data.mch_id}`;
    return http.get(url, {})
  },
  // 添加购物车
  postCartAdd: (data: { goods_id: number, attr: number, num: number }) => {
    const url = `api/cart/add`;
    return http.post(url, data)
  },

  // 购物车列表
  getCartList: () => {
    const url = `api/cart/list`;
    return http.post(url, {})
  },

  postDeleteCart: (data: { cart_id_list: string }) => {
    const url = `api/cart/delete`;
    return http.post(url, data)
  },

  // 查询订单状态 确认订单是否已支付
  getOrderStatus: (id: number) => {
    const url = `api/order/is-pay&payment_order_union_id=${id}`;
    return http.get(url, {})
  },

  // 取消订单
  getCancelOrder: (data:any) => {
    const url = `api/order/cancel&id=${data.id}&cancel_data: {"image_list":[],"remark":${data.remark},"mobile":${data.mobile},"cause":"多买/错买/不想要"}`;
    return http.get(url, {})
  },

  // 申请发票
  postInvoiceSubmit: (data:any) => {
    const url = `api/order/invoice-submit`;
    return http.post(url, data)
  },

  // 发票列表
  getInvoiceList: (data:any) => {
    const url = `api/order/invoice&status=${data.status}&page:${data.pageNum}`;
    return http.get(url, data)
  },
}


